/**
 * 请求组件的封装
 * @param {Object} url
 * @param {Object} data
 * @param {Object} method
 * @param {Object} contentType类型 1 json  2 表单
 */
function request (url,data,method="GET",contentType=1) {
	
	let heder = {
		'content-type':contentType ===1 ? 'application/json' : 'application/x-www-form-urlencoded'
	}
	
	let baseurl = '';
	
	return new Promise((reslove,reject) => {
		
		uni.request({
			url:baseurl + url ,
			data,
			method,
			header,
			success: (res) => {
				
				if (res.code === 200) {
					 reslove(res.data);
				}else if (res.code === 405) {
					uni.showToast({
						icon:'none',
						title:'未登录',
						duration:1500
					});
				}
				
			},
			fail: (error) => {
				
				uni.showToast({
					icon:'none',
					title:'请求失败',
					duration:1500
				});
			}
			
		})
		
	})
	
}



export default {request}

